package chainOfResponsibility;

import gameBasics.GameObject;

import java.util.LinkedList;
import java.util.List;

public class ColliderChain {

    private final List<Collider> colliders = new LinkedList<>();
    public ColliderChain(){
        addCollider(new BulletTankCollider());          //炮弹与坦克碰撞
        addCollider(new BulletWallCollider());          //炮弹与墙碰撞
        addCollider(new BulletIronCollider());          //炮弹与铁块碰撞
        addCollider(new BulletCommandPostCollider());   //炮弹与指挥所碰撞
        addCollider(new ETankETankCollider());          //敌对坦克与敌对坦克碰撞
        addCollider(new ETankWallCollider());           //敌对坦克与墙碰撞
        addCollider(new ETankIronCollider());           //敌对坦克与铁块碰撞
        addCollider(new ETankCommandPostCollider());    //敌对坦克与指挥所碰撞
        addCollider(new MTankETankCollider());          //主坦克与敌对坦克相撞
        addCollider(new MTankWallCollider());           //主坦克与墙碰撞
        addCollider(new MTankIronCollider());           //主坦克与铁块碰撞
        addCollider(new MTankCommandPostCollider());    //主坦克与指挥所碰撞
    }

    /**
     * 向碰撞责任链中添加碰撞器
     * @param collider 碰撞器对象
     */
    public void addCollider(Collider collider){
        colliders.add(collider);
    }

    /**
     * 碰撞责任链的碰撞判定
     * @param o1 游戏对象
     * @param o2 游戏对象
     */
    public void collide(GameObject o1, GameObject o2) {
        for (Collider collider : colliders) {
            if(!collider.collide(o1, o2)){
                break;
            }
        }
    }

}
